package com.zyf.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zyf.common.excption.YyghException;
import com.zyf.common.result.ResultCodeEnum;
import com.zyf.mapper.HospitalSetMapper;
import com.zyf.model.hosp.HospitalSet;
import com.zyf.service.HospitalSetService;
import com.zyf.vo.order.SignInfoVo;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;


@SuppressWarnings("all")
/**
 * @description: 医院设置 service实现类
 * @projectName:yygh_parent
 * @see:com.zyf.service.impl
 * @author:张忆敏
 * @createTime:2021/4/26 15:55
 * @version:1.0
 */
@Service
@Transactional
public class HospitalSetServiceImpl extends ServiceImpl<HospitalSetMapper, HospitalSet> implements HospitalSetService {


    /**
     * 根据医院编号获取医院签名
     *
     * @param hoscode 医院编号
     * @return String  SignKey
     * @author zyf
     * @date 2021/5/8 15:08
     */
    @Override
    public String getSignKey(String hoscode) {
        QueryWrapper<HospitalSet> wrapper = new QueryWrapper<>();
        wrapper.eq("hoscode", hoscode);
        HospitalSet hospitalSet = baseMapper.selectOne(wrapper);
        if (null == hospitalSet) {
            throw new YyghException(ResultCodeEnum.HOSPITAL_OPEN);
        }
        if (hospitalSet.getStatus().intValue() == 0) {
            throw new YyghException(ResultCodeEnum.HOSPITAL_LOCK);
        }
        return hospitalSet.getSignKey();
    }

    /**
     * 根据医院id，获取医院的签名信息
     * @author zyf
     * @date 2021/5/31 15:41
     * @param hoscode 医院编号
     * @return com.zyf.vo.order.SignInfoVo
     */
    @Override
    public SignInfoVo getSignInfoVo(String hoscode) {
        QueryWrapper<HospitalSet> wrapper = new QueryWrapper<>();
        wrapper.eq("hoscode",hoscode);
        HospitalSet hospitalSet = baseMapper.selectOne(wrapper);
        if (null == hospitalSet){
            throw new YyghException(ResultCodeEnum.HOSPITAL_OPEN);
        }
        SignInfoVo signInfoVo = new SignInfoVo();
        signInfoVo.setApiUrl(hospitalSet.getApiUrl())
                .setSignKey(hospitalSet.getSignKey());
        return signInfoVo;
    }
}
